import sqlite3
import math
import time
import sqlite_pub
from os.path import getsize

if __name__ == '__main__':
    table_name = 'pidata'
    filename = 'D:\\project\\C++\\PIInterface\\bin\\sqlite3\\pidata.sqlite3'
    conn = sqlite3.connect(filename)
    #conn = sqlite3.connect('D:\\pidata.sqlite3')

    c = conn.cursor()
    
    while 1:
        for i in range(0,20000):
            rval = math.sin(i/180.0*math.pi)*1000
            sql = "insert into pidata (pt, rval, ival, istat, datetime, type) values (14186, %f, %i, 0, %i, 'float')" % (rval,i,0)
            #print sql
            c.execute(sql)
                            
            rval = math.cos(i/180.0*math.pi)*1000
            sql = "insert into pidata (pt, rval, ival, istat, datetime, type) values (14187, %f, %i, 0, %i, 'float')" % (rval,i,0)
            #print sql
            c.execute(sql) 
            

        conn.commit() 
        #print 'insert', 2*i
        print 'row number = ', sqlite_pub.getrownum(c, table_name) 
        print 'file size = ', getsize(filename)
           
        time.sleep(1) 

    
    print 'end'